<template>
  <div class="powerexam" v-loading='loading'>
    <div class='bts-group'>
      <el-button v-for='(item,index) in uploadType'
                  :key='index'
                  @click='goPath(item.path)'
                  :class='activeIndex==index ? "sure":""'>{{item.name}}</el-button>
    </div>
    <h3 class="table-name">应急预案附件要素评审表</h3>
     <Table :data='data' ></Table>
    <div class="bts">

      <el-button class='sure' @click="saveData(0)">保存</el-button>
      <el-button class='sure'
                  @click='saveData(1)'>下一步</el-button>
    </div>
  </div>
</template>
<script>

import config from '../../config.js'
import Table from './common/table3'
export default {
  components: {
   Table
  },
  data () {
    return {
      data:[],
      leftImg:'',
      tit:"",
      signImg:'',
      autograph:'',
      varname:'',
      loading:false,
      radios: [1, 2, 3],
      uploadType: [
         {
          name: '形式评审',
          path: '/tableLay'
        },
        {
          name: '要素评审',
          path: '/tableLay/keyexam2'
        },
        {
          name: '附件要素评审',
          path: '/tableLay/powerexam2'
        },
        {
          name: '个人评审意见',
          path: '/tableLay/personexam2'
        }
      ],

      activeIndex: 2,
    };
  },
  mounted(){
     this.getData()
      this.signImg = localStorage.signImg
      this.autograph= localStorage.autograph
      this.$nextTick(()=>{
      document.querySelector('.left-box').style.height='816px'
    })
  },
  methods:{
    
    goPath(path){
      this.saveData(2,path)
    },
      getData(){
        this.loading=true
       this.postData(0, 7)
        .then( res=> {
           this.loading=false
            if (res.data.meta.success) {
                this.varname = res.data.data.companyName
                res.data.data.list.map((item,index)=>{
                   item.result=item.selectResult
                })
                 res.data.data.list.push({
                   reviewContent: '',
                   reviewItemOne: "注：附件根据应急工作需要而设置，部分项目可省略。",
                    reviewMethod: "",
                    tableType: "6",
                    flag:1,
                })
                res.data.data.list.push({
                  reviewContent: [this.signImg],
                  reviewItemOne: "评审专家签字",
                  reviewMethod: "",
                  tableType: "7",
                  flag:0,
                })
                this.data = res.data.data.list
            } else {
               this.$message.warning(res.data.meta.message)
            }
        })
        .catch(function (res) {
           console.log(res)
        })
    },
   
    saveData(n,path){
      
      let list=[]
      this.data.map((item,index)=>{
        if(index < (this.data.length-2)){
            list.push({
                  tableId:item.id,
                  result:item.result 
            })
        }
      })
      var flag = list.every(item=>{
         return (item.result!='' && item.result)
        })

      if(!flag){
         this.$message.warning('请选择完毕后再保存')
      }else{
       
      this.postData(2,7,list,this.autograph)
          .then(res => {
            if (res.data.meta.success) {
              if(n==1){
                 this.$router.push('personexam2')
              }else if(n==2){
               this.$router.push(path)
              }else{
                
              this.$message.success(res.data.meta.message)
              }
            } else {
              this.$message.warning(res.data.meta.message)
            }
          })
          .catch(response => {
            console.log(response);
          });
          

      }

    }
  }
}
</script>